package me.zhengjie.modules.quartz.task.snmp;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.quartz.domain.SnmpTrap;
import me.zhengjie.modules.quartz.repository.DeviceNetworkMsgRepository;
import org.snmp4j.PDU;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.springframework.stereotype.Component;

import java.util.List;


@Slf4j
@Component
@RequiredArgsConstructor
public class DeviceNetworkMsg extends TrapMsgSender {
    private static final String MSG_TYPE = "device";

    private final DeviceNetworkMsgRepository deviceNetworkMsgRepository;

    @Override
    public void handleTrapMsg() {
        // 1. 获取接入的设备信息
        List<SnmpTrap> devices = deviceNetworkMsgRepository.findByType(MSG_TYPE);

        devices.stream().forEach(d-> {
            pdu.add(new VariableBinding(new OID(d.getOid()), new OctetString(d.getValue())));
        });
        log.info("pdu size: {}", pdu.size());

    }
}
